home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Shape Smash / shape-smash.swf / scripts / mx / managers / FocusManager.as next >
Encoding:
Text File  |  2010-05-14  |  31.4 KB  |  985 lines

  1. package mx.managers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.display.InteractiveObject;
  6.    import flash.display.Sprite;
  7.    import flash.events.Event;
  8.    import flash.events.FocusEvent;
  9.    import flash.events.KeyboardEvent;
  10.    import flash.events.MouseEvent;
  11.    import flash.system.Capabilities;
  12.    import flash.text.TextField;
  13.    import flash.ui.Keyboard;
  14.    import mx.controls.Button;
  15.    import mx.core.FlexSprite;
  16.    import mx.core.IChildList;
  17.    import mx.core.IRawChildrenContainer;
  18.    import mx.core.IUIComponent;
  19.    import mx.core.mx_internal;
  20.    import mx.events.FlexEvent;
  21.    
  22.    use namespace mx_internal;
  23.    
  24.    public class FocusManager implements IFocusManager
  25.    {
  26.       mx_internal static const VERSION:String = "2.0.1.0";
  27.       
  28.       private var _showFocusIndicator:Boolean = false;
  29.       
  30.       private var focusableCandidates:Array;
  31.       
  32.       private var LARGE_TAB_INDEX:int = 99999;
  33.       
  34.       private var browserFocusComponent:InteractiveObject;
  35.       
  36.       private var calculateCandidates:Boolean = true;
  37.       
  38.       private var lastAction:String;
  39.       
  40.       private var focusableObjects:Array;
  41.       
  42.       private var defButton:Button;
  43.       
  44.       private var _form:IFocusManagerContainer;
  45.       
  46.       private var _defaultButtonEnabled:Boolean = true;
  47.       
  48.       private var activated:Boolean = false;
  49.       
  50.       private var _defaultButton:Button;
  51.       
  52.       private var _focusPane:Sprite;
  53.       
  54.       private var lastFocus:IFocusManagerComponent;
  55.       
  56.       private var browserMode:Boolean;
  57.       
  58.       public function FocusManager(param1:IFocusManagerContainer, param2:Boolean = false)
  59.       {
  60.          LARGE_TAB_INDEX = 99999;
  61.          calculateCandidates = true;
  62.          activated = false;
  63.          _showFocusIndicator = false;
  64.          _defaultButtonEnabled = true;
  65.          super();
  66.          browserMode = Capabilities.playerType == "ActiveX" && !param2;
  67.          param1.focusManager = this;
  68.          _form = param1;
  69.          focusableObjects = [];
  70.          focusPane = new FlexSprite();
  71.          focusPane.name = "focusPane";
  72.          addFocusables(DisplayObject(param1));
  73.          param1.addEventListener(Event.ADDED,addedHandler);
  74.          param1.addEventListener(Event.REMOVED,removedHandler);
  75.          param1.addEventListener(FlexEvent.SHOW,showHandler);
  76.          param1.addEventListener(FlexEvent.HIDE,hideHandler);
  77.          if(param1 != SystemManager(param1.systemManager).application)
  78.          {
  79.             param1.addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler);
  80.          }
  81.          param1.systemManager.addFocusManager(param1);
  82.       }
  83.       
  84.       private function addFocusables(param1:DisplayObject, param2:Boolean = false) : void
  85.       {
  86.          var focusable:IFocusManagerComponent = null;
  87.          var doc:DisplayObjectContainer = null;
  88.          var i:int = 0;
  89.          var rawChildren:IChildList = null;
  90.          var o:DisplayObject = param1;
  91.          var skipTopLevel:Boolean = param2;
  92.          if(o is IFocusManagerComponent && !skipTopLevel)
  93.          {
  94.             focusable = IFocusManagerComponent(o);
  95.             if(focusable.focusEnabled)
  96.             {
  97.                if(focusable.tabEnabled && isTabVisible(o))
  98.                {
  99.                   focusableObjects.push(o);
  100.                   calculateCandidates = true;
  101.                }
  102.                o.addEventListener("tabEnabledChange",tabEnabledChangeHandler);
  103.                o.addEventListener("tabIndexChange",tabIndexChangeHandler);
  104.             }
  105.          }
  106.          if(o is DisplayObjectContainer)
  107.          {
  108.             doc = DisplayObjectContainer(o);
  109.             o.addEventListener("tabChildrenChange",tabChildrenChangeHandler);
  110.             if(doc.tabChildren)
  111.             {
  112.                if(o is IRawChildrenContainer)
  113.                {
  114.                   rawChildren = IRawChildrenContainer(o).rawChildren;
  115.                   i = 0;
  116.                   while(i < rawChildren.numChildren)
  117.                   {
  118.                      try
  119.                      {
  120.                         addFocusables(rawChildren.getChildAt(i));
  121.                      }
  122.                      catch(error:SecurityError)
  123.                      {
  124.                      }
  125.                      i++;
  126.                   }
  127.                }
  128.                else
  129.                {
  130.                   i = 0;
  131.                   while(i < doc.numChildren)
  132.                   {
  133.                      try
  134.                      {
  135.                         addFocusables(doc.getChildAt(i));
  136.                      }
  137.                      catch(error:SecurityError)
  138.                      {
  139.                      }
  140.                      i++;
  141.                   }
  142.                }
  143.             }
  144.          }
  145.       }
  146.       
  147.       private function getChildIndex(param1:DisplayObjectContainer, param2:DisplayObject) : int
  148.       {
  149.          var parent:DisplayObjectContainer = param1;
  150.          var child:DisplayObject = param2;
  151.          try
  152.          {
  153.             return parent.getChildIndex(child);
  154.          }
  155.          catch(e:Error)
  156.          {
  157.             if(parent is IRawChildrenContainer)
  158.             {
  159.                return IRawChildrenContainer(parent).rawChildren.getChildIndex(child);
  160.             }
  161.             throw e;
  162.          }
  163.       }
  164.       
  165.       private function mouseFocusChangeHandler(param1:FocusEvent) : void
  166.       {
  167.          var _loc2_:TextField = null;
  168.          if(param1.relatedObject is TextField)
  169.          {
  170.             _loc2_ = param1.relatedObject as TextField;
  171.             if(_loc2_.type == "input" || _loc2_.selectable)
  172.             {
  173.                return;
  174.             }
  175.          }
  176.          param1.preventDefault();
  177.       }
  178.       
  179.       private function focusOutHandler(param1:FocusEvent) : void
  180.       {
  181.          var _loc2_:InteractiveObject = null;
  182.          _loc2_ = InteractiveObject(param1.target);
  183.       }
  184.       
  185.       private function isValidFocusCandidate(param1:DisplayObject, param2:String) : Boolean
  186.       {
  187.          var _loc3_:IFocusManagerGroup = null;
  188.          if(!isEnabledAndVisible(param1))
  189.          {
  190.             return false;
  191.          }
  192.          if(param1 is IFocusManagerGroup)
  193.          {
  194.             _loc3_ = IFocusManagerGroup(param1);
  195.             if(param2 == _loc3_.groupName)
  196.             {
  197.                return false;
  198.             }
  199.          }
  200.          return true;
  201.       }
  202.       
  203.       private function removeFocusables(param1:DisplayObject, param2:Boolean) : void
  204.       {
  205.          var _loc3_:int = 0;
  206.          if(param1 is DisplayObjectContainer)
  207.          {
  208.             if(!param2)
  209.             {
  210.                param1.removeEventListener("tabChildrenChange",tabChildrenChangeHandler);
  211.             }
  212.             _loc3_ = 0;
  213.             while(_loc3_ < focusableObjects.length)
  214.             {
  215.                if(isParent(DisplayObjectContainer(param1),focusableObjects[_loc3_]))
  216.                {
  217.                   if(focusableObjects[_loc3_] == lastFocus)
  218.                   {
  219.                      lastFocus.drawFocus(false);
  220.                      lastFocus = null;
  221.                   }
  222.                   focusableObjects[_loc3_].removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  223.                   focusableObjects[_loc3_].removeEventListener("tabIndexChange",tabIndexChangeHandler);
  224.                   focusableObjects.splice(_loc3_,1);
  225.                   _loc3_--;
  226.                   calculateCandidates = true;
  227.                }
  228.                _loc3_++;
  229.             }
  230.          }
  231.       }
  232.       
  233.       public function getFocus() : IFocusManagerComponent
  234.       {
  235.          var _loc1_:InteractiveObject = null;
  236.          _loc1_ = mx_internal::form.systemManager.stage.focus;
  237.          return findFocusManagerComponent(_loc1_);
  238.       }
  239.       
  240.       private function addedHandler(param1:Event) : void
  241.       {
  242.          var _loc2_:DisplayObject = null;
  243.          _loc2_ = DisplayObject(param1.target);
  244.          if(_loc2_.stage)
  245.          {
  246.             addFocusables(DisplayObject(param1.target));
  247.          }
  248.       }
  249.       
  250.       private function tabChildrenChangeHandler(param1:Event) : void
  251.       {
  252.          var _loc2_:DisplayObjectContainer = null;
  253.          if(param1.target != param1.currentTarget)
  254.          {
  255.             return;
  256.          }
  257.          calculateCandidates = true;
  258.          _loc2_ = DisplayObjectContainer(param1.target);
  259.          if(_loc2_.tabChildren)
  260.          {
  261.             addFocusables(_loc2_,true);
  262.          }
  263.          else
  264.          {
  265.             removeFocusables(_loc2_,true);
  266.          }
  267.       }
  268.       
  269.       private function sortByDepth(param1:IFocusManagerComponent, param2:IFocusManagerComponent) : Number
  270.       {
  271.          var _loc3_:String = null;
  272.          var _loc4_:String = null;
  273.          var _loc5_:int = 0;
  274.          var _loc6_:String = null;
  275.          var _loc7_:String = null;
  276.          var _loc8_:String = null;
  277.          var _loc9_:DisplayObject = null;
  278.          var _loc10_:DisplayObject = null;
  279.          _loc3_ = "";
  280.          _loc4_ = "";
  281.          _loc8_ = "0000";
  282.          _loc9_ = DisplayObject(param1);
  283.          _loc10_ = DisplayObject(param2);
  284.          while(_loc9_ != DisplayObject(mx_internal::form) && Boolean(_loc9_.parent))
  285.          {
  286.             _loc5_ = getChildIndex(_loc9_.parent,_loc9_);
  287.             _loc6_ = _loc5_.toString(16);
  288.             if(_loc6_.length < 4)
  289.             {
  290.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  291.             }
  292.             _loc3_ = _loc7_ + _loc3_;
  293.             _loc9_ = _loc9_.parent;
  294.          }
  295.          while(_loc10_ != DisplayObject(mx_internal::form) && Boolean(_loc10_.parent))
  296.          {
  297.             _loc5_ = getChildIndex(_loc10_.parent,_loc10_);
  298.             _loc6_ = _loc5_.toString(16);
  299.             if(_loc6_.length < 4)
  300.             {
  301.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  302.             }
  303.             _loc4_ = _loc7_ + _loc4_;
  304.             _loc10_ = _loc10_.parent;
  305.          }
  306.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : 0);
  307.       }
  308.       
  309.       mx_internal function sendDefaultButtonEvent() : void
  310.       {
  311.          defButton.dispatchEvent(new MouseEvent("click"));
  312.       }
  313.       
  314.       private function deactivateHandler(param1:Event) : void
  315.       {
  316.          var _loc2_:InteractiveObject = null;
  317.          _loc2_ = InteractiveObject(param1.target);
  318.       }
  319.       
  320.       private function tabIndexChangeHandler(param1:Event) : void
  321.       {
  322.          calculateCandidates = true;
  323.       }
  324.       
  325.       private function sortFocusableObjects() : void
  326.       {
  327.          var _loc1_:int = 0;
  328.          var _loc2_:int = 0;
  329.          var _loc3_:InteractiveObject = null;
  330.          focusableCandidates = [];
  331.          _loc1_ = int(focusableObjects.length);
  332.          _loc2_ = 0;
  333.          while(_loc2_ < _loc1_)
  334.          {
  335.             _loc3_ = focusableObjects[_loc2_];
  336.             if(_loc3_.tabIndex && !isNaN(Number(_loc3_.tabIndex)) && _loc3_.tabIndex > 0)
  337.             {
  338.                sortFocusableObjectsTabIndex();
  339.                return;
  340.             }
  341.             focusableCandidates.push(_loc3_);
  342.             _loc2_++;
  343.          }
  344.          focusableCandidates.sort(sortByDepth);
  345.       }
  346.       
  347.       private function keyFocusChangeHandler(param1:FocusEvent) : void
  348.       {
  349.          showFocusIndicator = true;
  350.          if(param1.keyCode == Keyboard.TAB && !param1.isDefaultPrevented())
  351.          {
  352.             if(browserFocusComponent)
  353.             {
  354.                if(browserFocusComponent.tabIndex == LARGE_TAB_INDEX)
  355.                {
  356.                   browserFocusComponent.tabIndex = -1;
  357.                }
  358.                browserFocusComponent = null;
  359.                return;
  360.             }
  361.             setFocusToNextObject(param1);
  362.             param1.preventDefault();
  363.          }
  364.       }
  365.       
  366.       private function getIndexOfFocusedObject(param1:DisplayObject) : int
  367.       {
  368.          var _loc2_:int = 0;
  369.          var _loc3_:int = 0;
  370.          _loc2_ = int(focusableCandidates.length);
  371.          _loc3_ = 0;
  372.          _loc3_ = 0;
  373.          while(_loc3_ < _loc2_)
  374.          {
  375.             if(focusableCandidates[_loc3_] == param1)
  376.             {
  377.                return _loc3_;
  378.             }
  379.             _loc3_++;
  380.          }
  381.          return -1;
  382.       }
  383.       
  384.       public function get nextTabIndex() : int
  385.       {
  386.          return getMaxTabIndex() + 1;
  387.       }
  388.       
  389.       public function get focusPane() : Sprite
  390.       {
  391.          return _focusPane;
  392.       }
  393.       
  394.       private function mouseDownHandler(param1:MouseEvent) : void
  395.       {
  396.          var _loc2_:DisplayObject = null;
  397.          if(param1.isDefaultPrevented())
  398.          {
  399.             return;
  400.          }
  401.          _loc2_ = getTopLevelFocusTarget(InteractiveObject(param1.target));
  402.          if(!_loc2_)
  403.          {
  404.             return;
  405.          }
  406.          showFocusIndicator = false;
  407.          if((_loc2_ != lastFocus || lastAction == "ACTIVATE") && !(_loc2_ is TextField))
  408.          {
  409.             setFocus(IFocusManagerComponent(_loc2_));
  410.          }
  411.          lastAction = "MOUSEDOWN";
  412.       }
  413.       
  414.       private function keyDownHandler(param1:KeyboardEvent) : void
  415.       {
  416.          var _loc2_:SystemManager = null;
  417.          var _loc3_:DisplayObject = null;
  418.          var _loc4_:String = null;
  419.          var _loc5_:int = 0;
  420.          var _loc6_:int = 0;
  421.          var _loc7_:IFocusManagerGroup = null;
  422.          _loc2_ = SystemManager(mx_internal::form.systemManager);
  423.          _loc2_.mx_internal::idleCounter = 0;
  424.          if(param1.keyCode == Keyboard.TAB)
  425.          {
  426.             lastAction = "KEY";
  427.             if(calculateCandidates)
  428.             {
  429.                sortFocusableObjects();
  430.                calculateCandidates = false;
  431.             }
  432.          }
  433.          if(browserMode)
  434.          {
  435.             if(param1.keyCode == Keyboard.TAB && focusableCandidates.length > 0)
  436.             {
  437.                _loc3_ = mx_internal::form.systemManager.stage.focus;
  438.                _loc3_ = DisplayObject(findFocusManagerComponent(InteractiveObject(_loc3_)));
  439.                _loc4_ = "";
  440.                if(_loc3_ is IFocusManagerGroup)
  441.                {
  442.                   _loc7_ = IFocusManagerGroup(_loc3_);
  443.                   _loc4_ = _loc7_.groupName;
  444.                }
  445.                _loc5_ = getIndexOfFocusedObject(_loc3_);
  446.                _loc6_ = getIndexOfNextObject(_loc5_,param1.shiftKey,false,_loc4_);
  447.                if(param1.shiftKey)
  448.                {
  449.                   if(_loc6_ >= _loc5_)
  450.                   {
  451.                      browserFocusComponent = mx_internal::form.systemManager.stage.focus;
  452.                      if(browserFocusComponent.tabIndex == -1)
  453.                      {
  454.                         browserFocusComponent.tabIndex = LARGE_TAB_INDEX;
  455.                      }
  456.                   }
  457.                }
  458.                else if(_loc6_ <= _loc5_)
  459.                {
  460.                   browserFocusComponent = mx_internal::form.systemManager.stage.focus;
  461.                   if(browserFocusComponent.tabIndex == -1)
  462.                   {
  463.                      browserFocusComponent.tabIndex = LARGE_TAB_INDEX;
  464.                   }
  465.                }
  466.             }
  467.          }
  468.          if(defaultButtonEnabled && param1.keyCode == Keyboard.ENTER && defaultButton && defButton.enabled)
  469.          {
  470.             defButton.callLater(mx_internal::sendDefaultButtonEvent);
  471.          }
  472.       }
  473.       
  474.       public function toString() : String
  475.       {
  476.          return Object(mx_internal::form).toString() + ".focusManager";
  477.       }
  478.       
  479.       private function focusInHandler(param1:FocusEvent) : void
  480.       {
  481.          var _loc2_:InteractiveObject = null;
  482.          var _loc3_:Button = null;
  483.          _loc2_ = InteractiveObject(param1.target);
  484.          if(isParent(DisplayObjectContainer(mx_internal::form),_loc2_))
  485.          {
  486.             lastFocus = findFocusManagerComponent(InteractiveObject(_loc2_));
  487.             if(lastFocus is Button)
  488.             {
  489.                _loc3_ = Button(lastFocus);
  490.                if(defButton)
  491.                {
  492.                   defButton.emphasized = false;
  493.                   defButton = _loc3_;
  494.                   _loc3_.emphasized = true;
  495.                }
  496.             }
  497.             else if(Boolean(defButton) && defButton != _defaultButton)
  498.             {
  499.                defButton.emphasized = false;
  500.                defButton = _defaultButton;
  501.                _defaultButton.emphasized = true;
  502.             }
  503.          }
  504.       }
  505.       
  506.       public function deactivate() : void
  507.       {
  508.          mx_internal::form.systemManager.stage.removeEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler);
  509.          mx_internal::form.systemManager.stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler);
  510.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  511.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  512.          mx_internal::form.systemManager.stage.removeEventListener(Event.ACTIVATE,activateHandler);
  513.          mx_internal::form.systemManager.stage.removeEventListener(Event.DEACTIVATE,deactivateHandler);
  514.          mx_internal::form.removeEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  515.          mx_internal::form.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  516.          activated = false;
  517.       }
  518.       
  519.       private function isParent(param1:DisplayObjectContainer, param2:DisplayObject) : Boolean
  520.       {
  521.          if(param1 is IRawChildrenContainer)
  522.          {
  523.             return IRawChildrenContainer(param1).rawChildren.contains(param2);
  524.          }
  525.          return param1.contains(param2);
  526.       }
  527.       
  528.       private function getIndexOfNextObject(param1:int, param2:Boolean, param3:Boolean, param4:String) : int
  529.       {
  530.          var _loc5_:int = 0;
  531.          var _loc6_:int = 0;
  532.          var _loc7_:DisplayObject = null;
  533.          var _loc8_:IFocusManagerGroup = null;
  534.          var _loc9_:int = 0;
  535.          var _loc10_:DisplayObject = null;
  536.          var _loc11_:IFocusManagerGroup = null;
  537.          _loc5_ = int(focusableCandidates.length);
  538.          _loc6_ = param1;
  539.          while(true)
  540.          {
  541.             if(param2)
  542.             {
  543.                param1--;
  544.             }
  545.             else
  546.             {
  547.                param1++;
  548.             }
  549.             if(param3)
  550.             {
  551.                if(param2 && param1 < 0)
  552.                {
  553.                   break;
  554.                }
  555.                if(!param2 && param1 == _loc5_)
  556.                {
  557.                   break;
  558.                }
  559.             }
  560.             else
  561.             {
  562.                param1 = (param1 + _loc5_) % _loc5_;
  563.                if(_loc6_ == param1)
  564.                {
  565.                   break;
  566.                }
  567.             }
  568.             if(isValidFocusCandidate(focusableCandidates[param1],param4))
  569.             {
  570.                _loc7_ = DisplayObject(findFocusManagerComponent(focusableCandidates[param1]));
  571.                if(_loc7_ is IFocusManagerGroup)
  572.                {
  573.                   _loc8_ = IFocusManagerGroup(_loc7_);
  574.                   _loc9_ = 0;
  575.                   while(_loc9_ < focusableCandidates.length)
  576.                   {
  577.                      _loc10_ = focusableCandidates[_loc9_];
  578.                      if(_loc10_ is IFocusManagerGroup)
  579.                      {
  580.                         _loc11_ = IFocusManagerGroup(_loc10_);
  581.                         if(_loc11_.groupName == _loc8_.groupName && _loc11_.selected)
  582.                         {
  583.                            param1 = _loc9_;
  584.                            break;
  585.                         }
  586.                      }
  587.                      _loc9_++;
  588.                   }
  589.                }
  590.                return param1;
  591.             }
  592.          }
  593.          return param1;
  594.       }
  595.       
  596.       private function getMaxTabIndex() : int
  597.       {
  598.          var _loc1_:Number = NaN;
  599.          var _loc2_:int = 0;
  600.          var _loc3_:int = 0;
  601.          var _loc4_:Number = NaN;
  602.          _loc1_ = 0;
  603.          _loc2_ = int(focusableObjects.length);
  604.          _loc3_ = 0;
  605.          while(_loc3_ < _loc2_)
  606.          {
  607.             _loc4_ = Number(focusableObjects[_loc3_].tabIndex);
  608.             if(!isNaN(_loc4_))
  609.             {
  610.                _loc1_ = Math.max(_loc1_,_loc4_);
  611.             }
  612.             _loc3_++;
  613.          }
  614.          return _loc1_;
  615.       }
  616.       
  617.       private function showHandler(param1:Event) : void
  618.       {
  619.          mx_internal::form.systemManager.activate(mx_internal::form);
  620.       }
  621.       
  622.       public function findFocusManagerComponent(param1:InteractiveObject) : IFocusManagerComponent
  623.       {
  624.          while(param1)
  625.          {
  626.             if(param1 is IFocusManagerComponent && IFocusManagerComponent(param1).focusEnabled)
  627.             {
  628.                return IFocusManagerComponent(param1);
  629.             }
  630.             param1 = param1.parent;
  631.          }
  632.          return null;
  633.       }
  634.       
  635.       public function setFocus(param1:IFocusManagerComponent) : void
  636.       {
  637.          param1.setFocus();
  638.       }
  639.       
  640.       mx_internal function set form(param1:IFocusManagerContainer) : void
  641.       {
  642.          _form = param1;
  643.       }
  644.       
  645.       private function sortFocusableObjectsTabIndex() : void
  646.       {
  647.          var _loc1_:int = 0;
  648.          var _loc2_:int = 0;
  649.          var _loc3_:IFocusManagerComponent = null;
  650.          focusableCandidates = [];
  651.          _loc1_ = int(focusableObjects.length);
  652.          _loc2_ = 0;
  653.          while(_loc2_ < _loc1_)
  654.          {
  655.             _loc3_ = focusableObjects[_loc2_];
  656.             if(Boolean(_loc3_.tabIndex) && !isNaN(Number(_loc3_.tabIndex)))
  657.             {
  658.                focusableCandidates.push(_loc3_);
  659.             }
  660.             _loc2_++;
  661.          }
  662.          focusableCandidates.sort(sortByTabIndex);
  663.       }
  664.       
  665.       public function set defaultButton(param1:IUIComponent) : void
  666.       {
  667.          var _loc2_:Button = null;
  668.          _loc2_ = !!param1 ? Button(param1) : null;
  669.          if(_loc2_ != _defaultButton)
  670.          {
  671.             if(_defaultButton)
  672.             {
  673.                _defaultButton.emphasized = false;
  674.             }
  675.             if(defButton)
  676.             {
  677.                defButton.emphasized = false;
  678.             }
  679.             _defaultButton = _loc2_;
  680.             defButton = _loc2_;
  681.             if(_loc2_)
  682.             {
  683.                _loc2_.emphasized = true;
  684.             }
  685.          }
  686.       }
  687.       
  688.       private function setFocusToNextObject(param1:FocusEvent) : void
  689.       {
  690.          var _loc2_:IFocusManagerComponent = null;
  691.          if(focusableObjects.length == 0)
  692.          {
  693.             return;
  694.          }
  695.          _loc2_ = getNextFocusManagerComponent(param1.shiftKey);
  696.          if(_loc2_)
  697.          {
  698.             setFocus(_loc2_);
  699.          }
  700.       }
  701.       
  702.       private function getTopLevelFocusTarget(param1:InteractiveObject) : InteractiveObject
  703.       {
  704.          while(param1 != InteractiveObject(mx_internal::form))
  705.          {
  706.             if(param1 is IFocusManagerComponent && IFocusManagerComponent(param1).focusEnabled && IFocusManagerComponent(param1).mouseFocusEnabled && IUIComponent(param1).enabled)
  707.             {
  708.                return param1;
  709.             }
  710.             param1 = param1.parent;
  711.             if(param1 == null)
  712.             {
  713.                break;
  714.             }
  715.          }
  716.          return null;
  717.       }
  718.       
  719.       private function hideHandler(param1:Event) : void
  720.       {
  721.          mx_internal::form.systemManager.deactivate(mx_internal::form);
  722.       }
  723.       
  724.       private function isEnabledAndVisible(param1:DisplayObject) : Boolean
  725.       {
  726.          var _loc2_:DisplayObjectContainer = null;
  727.          _loc2_ = DisplayObject(mx_internal::form).parent;
  728.          while(param1 != _loc2_)
  729.          {
  730.             if(param1 is IUIComponent)
  731.             {
  732.                if(!IUIComponent(param1).enabled)
  733.                {
  734.                   return false;
  735.                }
  736.             }
  737.             if(!param1.visible)
  738.             {
  739.                return false;
  740.             }
  741.             param1 = param1.parent;
  742.          }
  743.          return true;
  744.       }
  745.       
  746.       public function hideFocus() : void
  747.       {
  748.          if(showFocusIndicator)
  749.          {
  750.             showFocusIndicator = false;
  751.             if(lastFocus)
  752.             {
  753.                lastFocus.drawFocus(false);
  754.             }
  755.          }
  756.       }
  757.       
  758.       public function get showFocusIndicator() : Boolean
  759.       {
  760.          return _showFocusIndicator;
  761.       }
  762.       
  763.       mx_internal function get form() : IFocusManagerContainer
  764.       {
  765.          return _form;
  766.       }
  767.       
  768.       public function set focusPane(param1:Sprite) : void
  769.       {
  770.          _focusPane = param1;
  771.       }
  772.       
  773.       private function removedHandler(param1:Event) : void
  774.       {
  775.          var _loc2_:int = 0;
  776.          var _loc3_:DisplayObject = null;
  777.          _loc3_ = DisplayObject(param1.target);
  778.          if(_loc3_ is IFocusManagerComponent)
  779.          {
  780.             _loc2_ = 0;
  781.             while(_loc2_ < focusableObjects.length)
  782.             {
  783.                if(_loc3_ == focusableObjects[_loc2_])
  784.                {
  785.                   if(_loc3_ == lastFocus)
  786.                   {
  787.                      lastFocus.drawFocus(false);
  788.                      lastFocus = null;
  789.                   }
  790.                   _loc3_.removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  791.                   _loc3_.removeEventListener("tabIndexChange",tabIndexChangeHandler);
  792.                   focusableObjects.splice(_loc2_,1);
  793.                   calculateCandidates = true;
  794.                   break;
  795.                }
  796.                _loc2_++;
  797.             }
  798.          }
  799.          removeFocusables(_loc3_,false);
  800.       }
  801.       
  802.       private function activateHandler(param1:Event) : void
  803.       {
  804.          var _loc2_:InteractiveObject = null;
  805.          _loc2_ = InteractiveObject(param1.target);
  806.          if(Boolean(lastFocus) && !browserMode)
  807.          {
  808.             lastFocus.setFocus();
  809.          }
  810.          lastAction = "ACTIVATE";
  811.       }
  812.       
  813.       public function get defaultButton() : IUIComponent
  814.       {
  815.          return _defaultButton;
  816.       }
  817.       
  818.       public function showFocus() : void
  819.       {
  820.          if(!showFocusIndicator)
  821.          {
  822.             showFocusIndicator = true;
  823.             if(lastFocus)
  824.             {
  825.                lastFocus.drawFocus(true);
  826.             }
  827.          }
  828.       }
  829.       
  830.       public function getNextFocusManagerComponent(param1:Boolean = false) : IFocusManagerComponent
  831.       {
  832.          var _loc2_:DisplayObject = null;
  833.          var _loc3_:String = null;
  834.          var _loc4_:int = 0;
  835.          var _loc5_:Boolean = false;
  836.          var _loc6_:int = 0;
  837.          var _loc7_:int = 0;
  838.          var _loc8_:IFocusManagerGroup = null;
  839.          if(focusableObjects.length == 0)
  840.          {
  841.             return null;
  842.          }
  843.          if(calculateCandidates)
  844.          {
  845.             sortFocusableObjects();
  846.             calculateCandidates = false;
  847.          }
  848.          _loc2_ = mx_internal::form.systemManager.stage.focus;
  849.          _loc2_ = DisplayObject(findFocusManagerComponent(InteractiveObject(_loc2_)));
  850.          _loc3_ = "";
  851.          if(_loc2_ is IFocusManagerGroup)
  852.          {
  853.             _loc8_ = IFocusManagerGroup(_loc2_);
  854.             _loc3_ = _loc8_.groupName;
  855.          }
  856.          _loc4_ = getIndexOfFocusedObject(_loc2_);
  857.          _loc5_ = false;
  858.          _loc6_ = _loc4_;
  859.          if(_loc4_ == -1)
  860.          {
  861.             if(param1)
  862.             {
  863.                _loc4_ = int(focusableCandidates.length);
  864.             }
  865.             _loc5_ = true;
  866.          }
  867.          _loc7_ = getIndexOfNextObject(_loc4_,param1,_loc5_,_loc3_);
  868.          return findFocusManagerComponent(focusableCandidates[_loc7_]);
  869.       }
  870.       
  871.       public function set defaultButtonEnabled(param1:Boolean) : void
  872.       {
  873.          _defaultButtonEnabled = param1;
  874.       }
  875.       
  876.       private function isTabVisible(param1:DisplayObject) : Boolean
  877.       {
  878.          var _loc2_:DisplayObject = null;
  879.          var _loc3_:DisplayObjectContainer = null;
  880.          _loc2_ = DisplayObject(mx_internal::form.systemManager);
  881.          if(!_loc2_)
  882.          {
  883.             return false;
  884.          }
  885.          _loc3_ = param1.parent;
  886.          while(Boolean(_loc3_) && _loc3_ != _loc2_)
  887.          {
  888.             if(!_loc3_.tabChildren)
  889.             {
  890.                return false;
  891.             }
  892.             _loc3_ = _loc3_.parent;
  893.          }
  894.          return true;
  895.       }
  896.       
  897.       public function set showFocusIndicator(param1:Boolean) : void
  898.       {
  899.          _showFocusIndicator = param1;
  900.       }
  901.       
  902.       private function sortByTabIndex(param1:IFocusManagerComponent, param2:IFocusManagerComponent) : int
  903.       {
  904.          var _loc3_:int = 0;
  905.          var _loc4_:int = 0;
  906.          _loc3_ = param1.tabIndex;
  907.          _loc4_ = param2.tabIndex;
  908.          if(_loc3_ == -1)
  909.          {
  910.             _loc3_ = int.MAX_VALUE;
  911.          }
  912.          if(_loc4_ == -1)
  913.          {
  914.             _loc4_ = int.MAX_VALUE;
  915.          }
  916.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : int(sortByDepth(param1,param2)));
  917.       }
  918.       
  919.       public function activate() : void
  920.       {
  921.          if(activated)
  922.          {
  923.             return;
  924.          }
  925.          mx_internal::form.systemManager.stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler,false,0,true);
  926.          mx_internal::form.systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler,false,0,true);
  927.          mx_internal::form.addEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  928.          mx_internal::form.addEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  929.          mx_internal::form.systemManager.stage.addEventListener(Event.ACTIVATE,activateHandler,false,0,true);
  930.          mx_internal::form.systemManager.stage.addEventListener(Event.DEACTIVATE,deactivateHandler,false,0,true);
  931.          mx_internal::form.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  932.          mx_internal::form.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  933.          activated = true;
  934.          if(lastFocus)
  935.          {
  936.             setFocus(lastFocus);
  937.          }
  938.       }
  939.       
  940.       public function get defaultButtonEnabled() : Boolean
  941.       {
  942.          return _defaultButtonEnabled;
  943.       }
  944.       
  945.       private function creationCompleteHandler(param1:FlexEvent) : void
  946.       {
  947.          if(DisplayObject(mx_internal::form).visible && !activated)
  948.          {
  949.             mx_internal::form.systemManager.activate(mx_internal::form);
  950.          }
  951.       }
  952.       
  953.       private function tabEnabledChangeHandler(param1:Event) : void
  954.       {
  955.          var _loc2_:InteractiveObject = null;
  956.          var _loc3_:int = 0;
  957.          var _loc4_:int = 0;
  958.          calculateCandidates = true;
  959.          _loc2_ = InteractiveObject(param1.target);
  960.          _loc3_ = int(focusableObjects.length);
  961.          _loc4_ = 0;
  962.          while(_loc4_ < _loc3_)
  963.          {
  964.             if(focusableObjects[_loc4_] == _loc2_)
  965.             {
  966.                break;
  967.             }
  968.             _loc4_++;
  969.          }
  970.          if(_loc2_.tabEnabled)
  971.          {
  972.             if(_loc4_ == _loc3_ && isTabVisible(_loc2_))
  973.             {
  974.                focusableObjects.push(_loc2_);
  975.             }
  976.          }
  977.          else if(_loc4_ < _loc3_)
  978.          {
  979.             focusableObjects.splice(_loc4_,1);
  980.          }
  981.       }
  982.    }
  983. }
  984.  
  985.